function [share_d, profit_d] = get_share_e(x, N_d, m1_d_1, m0_d, N_k_0, alpha_price, alpha_population, population_log_d, alpha_distance, distance_d, delta_market, index_d, alpha_1, Y_d, expmu_market, nn, Y_market, prod_pct_d)

price_d = x(1:N_d, 1); 
q_d = x((N_d + 1):(2*N_d), 1); 
mc_e = x((2*N_d + 1):end, 1);

m1_d = ones(N_d, 1) * m1_d_1;
mc_d = exp(m0_d .* (q_d(1:N_k_0, 1) .^ m1_d(1:N_k_0, 1)));
mc_d = [mc_d; mc_e];

delta_d = q_d + log(price_d)*alpha_price + alpha_population*population_log_d + alpha_distance*distance_d;
expmeanval_market_counter = exp(delta_d);

expmu_d = exp(log(price_d)*alpha_1*Y_d);
expmu_market_counter = expmu_d;

marketForProducts_counter = ones(size(delta_d,1), 1);
sharesum_market_counter = sparse(zeros(1,size(delta_d,1)));
sharesum_market_counter(1,:) = 1;
oo = ones(1,nn);   
numer_counter = (expmeanval_market_counter*oo ).*expmu_market_counter;        
sum1 = sharesum_market_counter*numer_counter;
sum11 = 1./(0+sum1);                      
denom1 = sum11(marketForProducts_counter,:);    
simShare_counter = numer_counter.*denom1;              
EstShare_counter = mean(simShare_counter,2); 
share_d = EstShare_counter((end - N_d + 1):end);

profit_d = ((price_d - mc_d) ./ price_d) .* share_d;

end

